package com.youdoneed.friends.comments;

import com.youdoneed.base.application.ResultMessage;
import com.youdoneed.base.pagination.Page;
import com.youdoneed.friends.model.CommentsTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 留言模板操作请求控制器
 *
 * @author shum
 * @date 2017.7.20
 */
@RestController
@RequestMapping(value = "/commentsTemplate")
@Api(value = "留言模板操作请求控制器", description = "留言模板操作请求控制器")
public class CommentsTemplateController {

    private static final Logger logger = LoggerFactory.getLogger(CommentsTemplateController.class);
    @Autowired
    CommentsTemplateService commentsTemplateService;

    @RequestMapping(value = "/save", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "保存留言模板", value = "保存留言模板")
    public ResultMessage save(@ApiParam("内容") @RequestParam String content,
                              @ApiParam("用户id") @RequestParam(required = false) String userId) {
        CommentsTemplate record = new CommentsTemplate();
        record.setContent(content);
        record.setUserId(userId);
        commentsTemplateService.save(record);
        return new ResultMessage().toSuccess("保存留言模板成功");
    }

    @RequestMapping(value = "/delete", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "删除留言模板", value = "删除留言模板")
    public ResultMessage delete(@ApiParam("留言模板id") @RequestParam String templateId) {
        commentsTemplateService.delete(templateId);
        return new ResultMessage().toSuccess("删除留言模板成功");
    }

    @RequestMapping(value = "/update", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "更新留言模板", value = "更新留言模板")
    public ResultMessage update(@ApiParam("留言模板id") @RequestParam String templateId,
                                @ApiParam("内容") @RequestParam String content) {
        commentsTemplateService.update(templateId, content);
        return new ResultMessage().toSuccess("更新留言模板成功");
    }

    @RequestMapping(value = "/find", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "查询留言模板", value = "查询留言模板")
    public ResultMessage<Page<CommentsTemplate>> findStarFace(Paging paging, String userId) {
        return new ResultMessage<>(commentsTemplateService.findTemplate(paging, userId));
    }

    @RequestMapping(value = "/findByContent", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "查询留言模板（后台用）", value = "查询留言模板（后台用）")
    public ResultMessage<Page<CommentsTemplate>> findByContent(Paging paging, String content) {
        return new ResultMessage<>(commentsTemplateService.findListByContent(paging, content));
    }

    /**
     * 向上移动顺序。
     */
    @ApiOperation("向上移动顺序")
    @RequestMapping(value = "/sortMoveUp", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage sortMoveUp(String templateId) {
        commentsTemplateService.sortMoveUp(templateId);
        return new ResultMessage();
    }

    /**
     * 向下移动顺序。
     */
    @ApiOperation("向下移动顺序")
    @RequestMapping(value = "/sortMoveDown", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage sortMoveDown(String templateId) {
        commentsTemplateService.sortMoveDown(templateId);
        return new ResultMessage();
    }

}
